package com.ewzj.bigdata.mvp.ui.adapter

import android.view.View
import android.widget.ImageView

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.extensions.loadImgwithloading
import com.ewzj.bigdata.mvp.model.rspbean.DecPicBean
import com.ewzj.bigdata.mvp.ui.activity.PhotoPreViewActivity
import com.jakewharton.rxbinding2.view.RxView
import com.jess.arms.utils.UiUtils
import io.reactivex.Observable
import io.reactivex.functions.Consumer


import java.util.ArrayList


/**
 * author:zhangjing
 * 作用:
 * return:
 */

class NewItempicAdapter(data: List<DecPicBean>) : BaseQuickAdapter<DecPicBean, BaseViewHolder>(R.layout.item_newdecpic, data) {

    override fun convert(baseViewHolder: BaseViewHolder, decPicBean: DecPicBean) {
        (baseViewHolder.getView<View>(R.id.iv_pic) as ImageView).loadImgwithloading(decPicBean.thumb)
        baseViewHolder.setText(R.id.tv_title, if (decPicBean.pics == null) decPicBean.title + "(0张)" else decPicBean.title + "(" + decPicBean.pics.size + "张)")
        baseViewHolder.setText(R.id.tv_source, if (decPicBean.sources != null) "来源•" + decPicBean.sources else "来源•觅窝")
        baseViewHolder.getConvertView().setOnClickListener {
            Observable.just(decPicBean).map { t -> t.pics }.map { t ->
                {
                    val photos = ArrayList<String>()
                    for (pic in t) {
                        photos.add(pic.thumb)
                    }
                    photos
                }
            }
        }
        RxView.clicks(baseViewHolder.convertView).map { t -> decPicBean }.map { t -> t.pics }.map { t ->
            {
                val photos = ArrayList<String>()
                for (pic in t) {
                    photos.add(pic.thumb)
                }
                photos
            }
        }.subscribe(Consumer { t ->  PhotoPreViewActivity.startPhotoViewActivity(mContext,decPicBean.pics) })
    }
}